import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
// import axios from 'axios'

router.beforeEach((to, from, next) => {
  const loginye = '/'
  const topath = to.path // 点击 要去的页面
  // console.log(next)
  // console.log(localStorage.getItem('token'))
  const token = localStorage.getItem('token')
  if (!token && topath !== loginye) {
    // 判断。如果点击要去的页面不等于注册页面，就执行next，强制去登录
    next({ path: loginye, query: { redirect: to.fullPath } })
  }
  // 防止重复登录
  if (to.name === 'login' && token) {
    next({ name: 'content' })
  } else {
    next()
  }
})

createApp(App).use(store).use(router).use(Antd).mount('#app')
